<template>
    <!-- <div class="login-box">
        <h1>登录页</h1>
        <form>
            <input type="text" name="username" v-model="userName"> <br>
            <input type="text" name="age" v-model="age"> <br>
            <a href="javascript:;" @click="addUser">提交</a>
        </form>
    </div> -->
    <div class="bg-container">
        <div class="login-form">
            <div style="font-size: 20px; font-weight: 300; color: #fff">程序猿博客后台管理系统</div>
            <div>
                <el-form label-width="80px" class="login-box">
                    <el-form-item label="账号" prop="userName">
                        <el-input type="text" placeholder="请输入账号" v-model="userName" />
                    </el-form-item>
                    <el-form-item label="密码" prop="passWord">
                        <el-input type="password" placeholder="请输入密码" v-model="passWord" />
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">登录</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <div class="footer">
            <div class="copyright">
                <span>Copyright &copy; 2019 程序猿博客股份有限公司</span>
            </div>
        </div>
    </div>
</template>
<script>
import { setToken, setUserName } from "@/utils/auth";
import request from "@/utils/request";
export default {
  name: "login",
  data() {
    return {
      userName: "admin",
      passWord: "admin"
    };
  },
  methods: {
    onSubmit() {
      var userName = this.userName;
      var passWord = this.passWord;
      request({
        url: "/api/user/login",
        method: "post",
        data: {
          userName,
          passWord
        }
      }).then(res => {
        if (res.msg === "登录成功") {
          this.$message({
            message: "恭喜你，登录成功",
            type: "success"
          });
          setToken(res.token);
          setUserName(res.userName);
          this.$router.push("home");
        }
      });
    }
  }
};
</script>
<style scoped>
.el-form-item__label{
  color: #fff;
}
.bg-container {
  width: 100%;
  height: 900px;
  overflow: hidden;
  margin: 0;
  /* background-image: url('../../assets/login_bg.jpg'); */
}
.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  margin: 0 auto;
  height: 30px;
  line-height: 20px;
  padding-top: 5px;
  padding-bottom: 5px;
}
.footer .copyright {
  font-size: 12px;
  text-align: center;
  width: 100%;
  /* color: #fff; */
  opacity: 0.5;
}
.login-form {
  position: absolute;
  left: 50%;
  top: 35%;
  transform: translate(-50%, -50%);
}
/* h2 {
    color: #fff;
  } */
.login-box {
  border: 1px solid #dcdfe6;
  width: 350px;
  margin: 80px auto;
  padding: 35px 35px 15px 35px;
  border-radius: 5px;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  box-shadow: 0 0 25px #909399;
}
</style>